<?php 
header("content-type:text/html;charset=utf8");
$db=new PDO("mysql:host=127.0.0.1;dbname=bj07c;charset=utf8","root","root");
//开启缓存
$redis=new redis();
//连接
$redis->connect("127.0.0.1","6379");
$sql="select count(*) from addnew";
$res=$db->query($sql)->fetch();
// print_r($res);
//接值当前的page
$page=isset($_GET["page"])?$_GET["page"]:1;
//获取总条数
$total_num=$res["count(*)"];
//每页条数
$size=3;
//总页数
$total_page=ceil($total_num/$size);
// print_r($total_page);
//页面偏移量
$off=($page-1)*$size;
// print_r($off);die;
$datapage=$redis->get("res".$page);
if($datapage)
{
	echo "这是redis中的数据";
	$datapage=$redis->get("res".$page);
	//转换成数组
	$res=json_decode($datapage,true);
}
else
{
	$sql="select * from addnew limit $off,$size";
	// print_r($sql);die;
	$res=$db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
	// print_r($res);
	//转换成对象存在redis中
	$redisres=json_encode($res);
	$redis->set("res".$page,$redisres);
}

//上一页
$last_page=$page-1>0?$page-1:1;
//下一页
$next_page=$page+1>$total_page?$total_page:$page+1;
$str="<a href='show.php?page=1'>首页</a><a href='show.php?page=$last_page'>上一页</a><a href='show.php?page=$next_page'>下一页</a><a href='show.php?page=$total_page'>尾页</a>";
include("show.html");

 ?>